package com.yd.app.service.pc.agreementService;

import com.yd.app.mapper.AgreementMapper;
import com.yd.app.service.common.BaseService;
import com.yd.domain.business.Agreement;
import com.yd.domain.commom.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 优惠券Service
 * Created by sunxianhui on 2018/3/9.
 */
@Service
public class AgreementService extends BaseService {

    @Autowired
    AgreementMapper agreementMapper;
    /**
     * 添加协议
     * @param agreement
     */
    public void addAgreement(Agreement agreement) {
        agreementMapper.addAgreement(agreement);
    }
    /**
     * 修改协议
     * @param agreement
     */
    public void updateAgreement(Agreement agreement) {
        agreementMapper.updateAgreement(agreement);
    }
    /**
     * 删除协议
     */
    public void deleteAgreementById(String id) {
        agreementMapper.deleteAgreementById(id);
    }


    public PageModel getAgreementList(Agreement agreement, int pageIndex, int pageSize) {
        PageModel pm = new PageModel();
        int startRow = getStartRow(pageIndex, pageSize);
        List<Agreement> agreementList = agreementMapper.getAgreementList(agreement, startRow, pageSize);
        int count = 0;
        if (pageIndex == 1) {
            //查询总条数
            count = agreementMapper.getAgreementListCount(agreement);
            pm.setCount(count);
        }
        pm.setList(agreementList);
        return pm;
    }

    public List<Agreement> getAgreementList() {
        List<Agreement> list=agreementMapper.getAgreementListAll();
        return list;
    }

    public Agreement getAgreementDetail(String id) {
       return agreementMapper.getAgreementDetail(id);
    }
    /**
     * 根据条件分页查询
     *
     * @param coupon
     * @param pageIndex
     * @param pageSize
     * @return
     */
    /*public PageModel getCouponList(Coupon coupon, int pageIndex, int pageSize) {
        PageModel pm = new PageModel();
        int startRow = getStartRow(pageIndex, pageSize);
        List<Coupon> couponList = couponMapper.getCouponList(coupon, startRow, pageSize);
        int count = 0;
        if (pageIndex == 1) {
            //查询总条数
            count = couponMapper.getCouponCount(coupon);
            pm.setCount(count);
        }
        pm.setList(couponList);
        return pm;
    }
*/

}